package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.CommonRouteDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ICommonRouteConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@Auth
@RestController
@RequestMapping({ "/commonRoute" }) 
@Api("CommonRouteController相关api")
@CrossOrigin
public class CommonRouteController {
	@Autowired
	private ICommonRouteConsumeService iCommonRouteConsumeService;
	
	/**
	 * 获取常备线路分页；
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
    @GetMapping(value = { "/getCommonRoutePage" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation(value = "常备线路分页", notes = "常备线路分页")
    	@ApiImplicitParams({
        @ApiImplicitParam(name = "commonRouteId", value = "常备线路编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "commonRouteName", value = "常备线路名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "routeStartPlace", value = "起始位置名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "routeTargetPlace", value = "终止位置名称", paramType = "query", dataType = "string")})
    public ResultPojo getCommonPlacePage(
			@RequestParam(defaultValue = "") String commonRouteId,
			@RequestParam(defaultValue = "") String commonRouteName, 
			@RequestParam(defaultValue = "") String routeStartPlace, 
			@RequestParam(defaultValue = "") String routeTargetPlace,
    		Page page, HttpServletRequest request){
    	ResultPojo resultPojo = new ResultPojo();
    	resultPojo = iCommonRouteConsumeService.getCommonRoutePage(page, commonRouteId, commonRouteName, routeStartPlace, routeTargetPlace);
    	return resultPojo;
    }
	/**
	 * 获取常备单位List；
	 * @return
	 */
	@GetMapping(value = { "/getCommonRouteList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
    @ApiOperation("常备线路List查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "commonRouteId", value = "常备线路编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "commonRouteName", value = "常备线路名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "routeStartPlace", value = "起始位置名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "routeTargetPlace", value = "终止位置名称", paramType = "query", dataType = "string")})
	public ResultPojo getCommonPlaceList( 
			@RequestParam(defaultValue = "") String commonRouteId,
			@RequestParam(defaultValue = "") String commonRouteName, 
			@RequestParam(defaultValue = "") String routeStartPlace, 
			@RequestParam(defaultValue = "") String routeTargetPlace,
    		HttpServletRequest request) {
		return iCommonRouteConsumeService.getCommonRouteList(commonRouteId, commonRouteName, routeStartPlace, routeTargetPlace);
	}
	/**
	 * 添加常备线路；
	 * @return
	 */
	@PostMapping(value = { "/addCommonRoute" }, consumes = { "application/json; charset=UTF-8" }, produces = {
	"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加常备线路")
	public ResultPojo addCommonRoute(@RequestBody CommonRouteDto commonRouteDto, HttpServletRequest request) {
		return iCommonRouteConsumeService.addCommonRoute(commonRouteDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 修改常备线路；
	 * @return
	 */
	@PutMapping(value = { "/editCommonRoute" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改常备线路")
	public ResultPojo editCommonRoute(@RequestBody CommonRouteDto commonRouteDto, HttpServletRequest request) {
		return iCommonRouteConsumeService.editCommonRoute(commonRouteDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 删除常备线路；
	 * @return
	 */
	@DeleteMapping(value = { "/delCommonRoute" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除常备线路")
    @ApiImplicitParam(name = "commonRouteId", value = "commonRouteId", paramType = "query", required = true, dataType = "String")
    public ResultPojo delCommonPlace(
    		@RequestParam(defaultValue = "",value="commonRouteId", required=true) String commonRouteId,
    		HttpServletRequest request) {
        return iCommonRouteConsumeService.deleteCommonRoute(commonRouteId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
}
